<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>达内－NetCTOSS</title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" /> 
        <script language="javascript" type="text/javascript" src="../js/jquery-1.4.3.js"></script>
        <script language="javascript" type="text/javascript">
            //显示角色详细信息
            function showDetail(flag, a) {
                var detailDiv = a.parentNode.getElementsByTagName("div")[0];
                if (flag) {
                    detailDiv.style.display = "block";
                }
                else
                    detailDiv.style.display = "none";
            }
            //重置密码
            function resetPwd() {
                //找到全部复选框
                var checkObjs = document.getElementsByName("checkAdmin");
                //遍历全部复选框，从中找出选中的
                var idArray = new Array();
                for(var i=0; i<checkObjs.length;i++){
                	var checkObj = checkObjs[i];
                	//如果没选中，则结束本次循环
                	if(!checkObj.checked) continue;
                	//如果选中了，找该文本框的爷爷，即行对象
                	var trObj = checkObj.parentNode.parentNode;
                	//找该行对象所有的孩子td
                	var tdObjs = trObj.getElementsByTagName("td");
                	//下标为1的td是所在的列
                	var idTdObj = tdObjs[1];
                	//从id所在列对象中取出ID值
                	var id = idTdObj.innerHTML;
                	idArray.push(id);
                }
                if(idArray.length == 0){
                	alert("请选择要重置密码的数据");
                	return;
                }
                //进行重置密码
                $.post("resetPassword",{"ids":idArray.toString()},function(data){
                	var ok = data;
                	if(ok) {
                		$("#operate_result_info").text("密码重置成功");
                		showResultDiv(true);
                		window.setTimeout("showResultDiv(false);", 1000);
                	} else {
                		$("#operate_result_info").text("密码重置失败");
                		showResultDiv(true);
                		window.setTimeout("showResultDiv(false);", 1000);
                	}
                });
            }
            //删除
            function deleteAdmin(id) {
                var r = window.confirm("确定要删除此管理员吗？");
                if(r){
                	$("#"+id).hide();
                	$.post("deleteAdmin",{"id":id},function(data){
                		var ok = data;
                		if(ok){
                			$("#operate_result_info").text("删除成功").attr("style","display : block");
				        	setTimeout($("#operate_result_info").attr("style","display : none"),1000);
                		}else{
                			$("#operate_result_info").text("删除失败，请刷新重试").attr("style","display : block");
				        	setTimeout($("#operate_result_info").attr("style","display : none"),1000);
                		}
                	});
                }
            }
            //全选
            function selectAdmins(inputObj) {
                var inputArray = document.getElementById("datalist").getElementsByTagName("input");
                for (var i = 1; i < inputArray.length; i++) {
                    if (inputArray[i].type == "checkbox") {
                        inputArray[i].checked = inputObj.checked;
                    }
                }
            }
            function toPage(page){
            	document.getElementById("currPage").value=page;
            	document.forms[0].submit();
            }
            
            function showResultDiv(flag) {
                var divResult = document.getElementById("operate_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }
        </script>       
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="#">[退出]</a>            
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">                        
            <ul id="menu">
                <li><a href="../index/index" class="index_off"></a></li>
                <li><a href="../role/findRole" class="role_off"></a></li>
                <li><a href="../admin/findAdmin" class="admin_on"></a></li>
                <li><a href="../cost/findCost" class="fee_off"></a></li>
                <li><a href="../account/findAccount" class="account_off"></a></li>
                <li><a href="../service/findService" class="service_off"></a></li>
                <li><a href="../bill/findBill" class="bill_off"></a></li>
                <li><a href="../report/findReport" class="report_off"></a></li>
                <li><a href="../user/userInfo" class="information_off"></a></li>
                <li><a href="../user/userModiPwd" class="password_off"></a></li>
            </ul>            
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">
            <form action="" method="post">
            <s:hidden name="page" id = "currPage"></s:hidden>
                <!--查询-->
                <div class="search_add">
                    <div>
                        模块：
                        <s:select cssClass="select_search" name="roleId" list="roles" listKey="id" listValue="name" id="selModules" emptyOption="-1"></s:select>
                    </div>
                    <div>角色：<input type="text" value="" class="text_search width200" name="privilegeId"/></div>
                    <div><input type="submit" value="搜索" class="btn_search"/></div>
                    <input type="button" value="密码重置" class="btn_add" onclick="resetPwd();" />
                    <input type="button" value="增加" class="btn_add" onclick="location.href='toAddAdmin';" />
                </div>
                <!--删除和密码重置的操作提示-->
                <div id="operate_result_info" class="operate_fail">
                    <img src="../images/close.png" onclick="this.parentNode.style.display='none';" />
                    <span>删除失败！数据并发错误。</span><!--密码重置失败！数据并发错误。-->
                </div> 
                <!--数据区域：用表格展示数据-->     
                <div id="data">            
                    <table id="datalist">
                        <tr>
                            <th class="th_select_all">
                                <input type="checkbox" onclick="selectAdmins(this);"/>
                                <span>全选</span>
                            </th>
                            <th>管理员ID</th>
                            <th>姓名</th>
                            <th>登录名</th>
                            <th>电话</th>
                            <th>电子邮件</th>
                            <th>授权日期</th>
                            <th class="width100">拥有角色</th>
                            <th></th>
                        </tr>   
                        <s:iterator value="admins">
                        	<tr id="<s:property value="id"/>">
                        		<td><input type="checkbox" name="checkAdmin"/></td>
                        		<td><s:property value="id"/></td>
                        		<td><s:property value="name"/></td>
                        		<td><s:property value="adminCode"/></td>
                        		<td><s:property value="telephone"/></td>
                        		<td><s:property value="email"/></td>
                        		<td><s:property value="enrollDateS"/></td>
                        		<td>
                                	<a class="summary"  onmouseover="showDetail(true,this);" onmouseout="showDetail(false,this);">更多...</a>
                                	<!-- 浮动的详细信息 -->
                                	<div class="detail_info" >
                                    <s:property value="roleName"/>
                                </div>
                            	</td>
                            	<td class="td_modi">
                                	<input type="button" value="修改" class="btn_modify" onclick="location.href='updateAdmin?id=<s:property value="id"/>';" />
                                	<input type="button" value="删除" class="btn_delete" onclick="deleteAdmin(<s:property value="id"/>);" />
                            	</td>
                        	</tr>
                        </s:iterator>
                    </table>
                </div>
                <!--分页-->
                <div id="pages">
        	        <s:if test="page==1">
                		<a href="#">上一页</a>
                	</s:if>
                	<s:else>
                		<a href="findAdmin.action?page=<s:property value="page-1"/>">上一页</a>
                	</s:else>
                    
                    <s:iterator begin="1" end="totalPage" var="p">
                    	<s:if test="#p==page">
                    		<a href="findAdmin.action?page=<s:property/>" class="current_page"><s:property/></a>
                    	</s:if>
                    	<s:else>
                    		<a href="findAdmin.action?page=<s:property/>"><s:property/></a>
                    	</s:else>
                    </s:iterator>
                    
                    <s:if test="page==totalPage">
                    	<a href="#">下一页</a>
                    </s:if>
                    <s:else>
                    	<a href="findAdmin.action?page=<s:property value="page+1"/>">下一页</a>
                    </s:else>
                </div>                    
            </form>
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
            <p>版权所有(C)加拿大达内IT培训集团公司 </p>
        </div>
    </body>
</html>

